using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace BookShop
{
	/// <summary>
	/// Strongly-typed collection for the Task class.
	/// </summary>
    [Serializable]
	public partial class TaskCollection : ActiveList<Task, TaskCollection>
	{	   
		public TaskCollection() {}
        
        /// <summary>
		/// Filters an existing collection based on the set criteria. This is an in-memory filter
		/// Thanks to developingchris for this!
        /// </summary>
        /// <returns>TaskCollection</returns>
		public TaskCollection Filter()
        {
            for (int i = this.Count - 1; i > -1; i--)
            {
                Task o = this[i];
                foreach (SubSonic.Where w in this.wheres)
                {
                    bool remove = false;
                    System.Reflection.PropertyInfo pi = o.GetType().GetProperty(w.ColumnName);
                    if (pi.CanRead)
                    {
                        object val = pi.GetValue(o, null);
                        switch (w.Comparison)
                        {
                            case SubSonic.Comparison.Equals:
                                if (!val.Equals(w.ParameterValue))
                                {
                                    remove = true;
                                }
                                break;
                        }
                    }
                    if (remove)
                    {
                        this.Remove(o);
                        break;
                    }
                }
            }
            return this;
        }
		
		
	}
	/// <summary>
	/// This is an ActiveRecord class which wraps the Task table.
	/// </summary>
	[Serializable]
	public partial class Task : ActiveRecord<Task>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public Task()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}
		
		private void InitSetDefaults() { SetDefaults(); }
		
		public Task(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}
        
		public Task(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}
		 
		public Task(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}
		
		protected static void SetSQLProps() { GetTableSchema(); }
		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}
		}
		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("Task", TableType.Table, DataService.GetInstance("BookShop"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarTaskID = new TableSchema.TableColumn(schema);
				colvarTaskID.ColumnName = "TaskID";
				colvarTaskID.DataType = DbType.Int32;
				colvarTaskID.MaxLength = 0;
				colvarTaskID.AutoIncrement = true;
				colvarTaskID.IsNullable = false;
				colvarTaskID.IsPrimaryKey = true;
				colvarTaskID.IsForeignKey = false;
				colvarTaskID.IsReadOnly = false;
				colvarTaskID.DefaultSetting = @"";
				colvarTaskID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarTaskID);
				
				TableSchema.TableColumn colvarFlowID = new TableSchema.TableColumn(schema);
				colvarFlowID.ColumnName = "FlowID";
				colvarFlowID.DataType = DbType.AnsiStringFixedLength;
				colvarFlowID.MaxLength = 10;
				colvarFlowID.AutoIncrement = false;
				colvarFlowID.IsNullable = true;
				colvarFlowID.IsPrimaryKey = false;
				colvarFlowID.IsForeignKey = false;
				colvarFlowID.IsReadOnly = false;
				colvarFlowID.DefaultSetting = @"";
				colvarFlowID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarFlowID);
				
				TableSchema.TableColumn colvarOrder = new TableSchema.TableColumn(schema);
				colvarOrder.ColumnName = "Order";
				colvarOrder.DataType = DbType.Int32;
				colvarOrder.MaxLength = 0;
				colvarOrder.AutoIncrement = false;
				colvarOrder.IsNullable = true;
				colvarOrder.IsPrimaryKey = false;
				colvarOrder.IsForeignKey = false;
				colvarOrder.IsReadOnly = false;
				colvarOrder.DefaultSetting = @"";
				colvarOrder.ForeignKeyTableName = "";
				schema.Columns.Add(colvarOrder);
				
				TableSchema.TableColumn colvarInitiator = new TableSchema.TableColumn(schema);
				colvarInitiator.ColumnName = "Initiator";
				colvarInitiator.DataType = DbType.AnsiStringFixedLength;
				colvarInitiator.MaxLength = 10;
				colvarInitiator.AutoIncrement = false;
				colvarInitiator.IsNullable = true;
				colvarInitiator.IsPrimaryKey = false;
				colvarInitiator.IsForeignKey = false;
				colvarInitiator.IsReadOnly = false;
				colvarInitiator.DefaultSetting = @"";
				colvarInitiator.ForeignKeyTableName = "";
				schema.Columns.Add(colvarInitiator);
				
				TableSchema.TableColumn colvarInitialDepartment = new TableSchema.TableColumn(schema);
				colvarInitialDepartment.ColumnName = "InitialDepartment";
				colvarInitialDepartment.DataType = DbType.String;
				colvarInitialDepartment.MaxLength = 50;
				colvarInitialDepartment.AutoIncrement = false;
				colvarInitialDepartment.IsNullable = true;
				colvarInitialDepartment.IsPrimaryKey = false;
				colvarInitialDepartment.IsForeignKey = false;
				colvarInitialDepartment.IsReadOnly = false;
				colvarInitialDepartment.DefaultSetting = @"";
				colvarInitialDepartment.ForeignKeyTableName = "";
				schema.Columns.Add(colvarInitialDepartment);
				
				TableSchema.TableColumn colvarInitialDate = new TableSchema.TableColumn(schema);
				colvarInitialDate.ColumnName = "InitialDate";
				colvarInitialDate.DataType = DbType.DateTime;
				colvarInitialDate.MaxLength = 0;
				colvarInitialDate.AutoIncrement = false;
				colvarInitialDate.IsNullable = true;
				colvarInitialDate.IsPrimaryKey = false;
				colvarInitialDate.IsForeignKey = false;
				colvarInitialDate.IsReadOnly = false;
				colvarInitialDate.DefaultSetting = @"";
				colvarInitialDate.ForeignKeyTableName = "";
				schema.Columns.Add(colvarInitialDate);
				
				TableSchema.TableColumn colvarStatus = new TableSchema.TableColumn(schema);
				colvarStatus.ColumnName = "Status";
				colvarStatus.DataType = DbType.AnsiStringFixedLength;
				colvarStatus.MaxLength = 10;
				colvarStatus.AutoIncrement = false;
				colvarStatus.IsNullable = true;
				colvarStatus.IsPrimaryKey = false;
				colvarStatus.IsForeignKey = false;
				colvarStatus.IsReadOnly = false;
				colvarStatus.DefaultSetting = @"";
				colvarStatus.ForeignKeyTableName = "";
				schema.Columns.Add(colvarStatus);
				
				TableSchema.TableColumn colvarSource = new TableSchema.TableColumn(schema);
				colvarSource.ColumnName = "Source";
				colvarSource.DataType = DbType.AnsiString;
				colvarSource.MaxLength = 50;
				colvarSource.AutoIncrement = false;
				colvarSource.IsNullable = true;
				colvarSource.IsPrimaryKey = false;
				colvarSource.IsForeignKey = false;
				colvarSource.IsReadOnly = false;
				colvarSource.DefaultSetting = @"";
				colvarSource.ForeignKeyTableName = "";
				schema.Columns.Add(colvarSource);
				
				TableSchema.TableColumn colvarApprovalID = new TableSchema.TableColumn(schema);
				colvarApprovalID.ColumnName = "ApprovalID";
				colvarApprovalID.DataType = DbType.AnsiStringFixedLength;
				colvarApprovalID.MaxLength = 20;
				colvarApprovalID.AutoIncrement = false;
				colvarApprovalID.IsNullable = true;
				colvarApprovalID.IsPrimaryKey = false;
				colvarApprovalID.IsForeignKey = false;
				colvarApprovalID.IsReadOnly = false;
				colvarApprovalID.DefaultSetting = @"";
				colvarApprovalID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarApprovalID);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["BookShop"].AddSchema("Task",schema);
			}
		}
		#endregion
		
		#region Props
		  
		[XmlAttribute("TaskID")]
		[Bindable(true)]
		public int TaskID 
		{
			get { return GetColumnValue<int>(Columns.TaskID); }
			set { SetColumnValue(Columns.TaskID, value); }
		}
		  
		[XmlAttribute("FlowID")]
		[Bindable(true)]
		public string FlowID 
		{
			get { return GetColumnValue<string>(Columns.FlowID); }
			set { SetColumnValue(Columns.FlowID, value); }
		}
		  
		[XmlAttribute("Order")]
		[Bindable(true)]
		public int? Order 
		{
			get { return GetColumnValue<int?>(Columns.Order); }
			set { SetColumnValue(Columns.Order, value); }
		}
		  
		[XmlAttribute("Initiator")]
		[Bindable(true)]
		public string Initiator 
		{
			get { return GetColumnValue<string>(Columns.Initiator); }
			set { SetColumnValue(Columns.Initiator, value); }
		}
		  
		[XmlAttribute("InitialDepartment")]
		[Bindable(true)]
		public string InitialDepartment 
		{
			get { return GetColumnValue<string>(Columns.InitialDepartment); }
			set { SetColumnValue(Columns.InitialDepartment, value); }
		}
		  
		[XmlAttribute("InitialDate")]
		[Bindable(true)]
		public DateTime? InitialDate 
		{
			get { return GetColumnValue<DateTime?>(Columns.InitialDate); }
			set { SetColumnValue(Columns.InitialDate, value); }
		}
		  
		[XmlAttribute("Status")]
		[Bindable(true)]
		public string Status 
		{
			get { return GetColumnValue<string>(Columns.Status); }
			set { SetColumnValue(Columns.Status, value); }
		}
		  
		[XmlAttribute("Source")]
		[Bindable(true)]
		public string Source 
		{
			get { return GetColumnValue<string>(Columns.Source); }
			set { SetColumnValue(Columns.Source, value); }
		}
		  
		[XmlAttribute("ApprovalID")]
		[Bindable(true)]
		public string ApprovalID 
		{
			get { return GetColumnValue<string>(Columns.ApprovalID); }
			set { SetColumnValue(Columns.ApprovalID, value); }
		}
		
		#endregion
		
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(string varFlowID,int? varOrder,string varInitiator,string varInitialDepartment,DateTime? varInitialDate,string varStatus,string varSource,string varApprovalID)
		{
			Task item = new Task();
			
			item.FlowID = varFlowID;
			
			item.Order = varOrder;
			
			item.Initiator = varInitiator;
			
			item.InitialDepartment = varInitialDepartment;
			
			item.InitialDate = varInitialDate;
			
			item.Status = varStatus;
			
			item.Source = varSource;
			
			item.ApprovalID = varApprovalID;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varTaskID,string varFlowID,int? varOrder,string varInitiator,string varInitialDepartment,DateTime? varInitialDate,string varStatus,string varSource,string varApprovalID)
		{
			Task item = new Task();
			
				item.TaskID = varTaskID;
			
				item.FlowID = varFlowID;
			
				item.Order = varOrder;
			
				item.Initiator = varInitiator;
			
				item.InitialDepartment = varInitialDepartment;
			
				item.InitialDate = varInitialDate;
			
				item.Status = varStatus;
			
				item.Source = varSource;
			
				item.ApprovalID = varApprovalID;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn TaskIDColumn
        {
            get { return Schema.Columns[0]; }
        }
        
        
        
        public static TableSchema.TableColumn FlowIDColumn
        {
            get { return Schema.Columns[1]; }
        }
        
        
        
        public static TableSchema.TableColumn OrderColumn
        {
            get { return Schema.Columns[2]; }
        }
        
        
        
        public static TableSchema.TableColumn InitiatorColumn
        {
            get { return Schema.Columns[3]; }
        }
        
        
        
        public static TableSchema.TableColumn InitialDepartmentColumn
        {
            get { return Schema.Columns[4]; }
        }
        
        
        
        public static TableSchema.TableColumn InitialDateColumn
        {
            get { return Schema.Columns[5]; }
        }
        
        
        
        public static TableSchema.TableColumn StatusColumn
        {
            get { return Schema.Columns[6]; }
        }
        
        
        
        public static TableSchema.TableColumn SourceColumn
        {
            get { return Schema.Columns[7]; }
        }
        
        
        
        public static TableSchema.TableColumn ApprovalIDColumn
        {
            get { return Schema.Columns[8]; }
        }
        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string TaskID = @"TaskID";
			 public static string FlowID = @"FlowID";
			 public static string Order = @"Order";
			 public static string Initiator = @"Initiator";
			 public static string InitialDepartment = @"InitialDepartment";
			 public static string InitialDate = @"InitialDate";
			 public static string Status = @"Status";
			 public static string Source = @"Source";
			 public static string ApprovalID = @"ApprovalID";
						
		}
		#endregion
		
		#region Update PK Collections
		
        #endregion
    
        #region Deep Save
		
        #endregion
	}
}
